package org.liziyi.huffman.config;

import java.awt.*;
import java.util.Properties;

/**
 * 全局配置类
 *
 * @author liziyi
 */
public class Config {
    public static  int fileChooseGUIWidth;
    public static  int fileChooseGUIHeight;
    public static  int fileDisplayGUIWidth;
    public static  int fileDisplayGUIHeight;
    public static  int treeDisplayGUIWidth;
    public static  int treeDisplayGUIHeight;
    public static  int treeBasePositionX;
    public static  int treeBasePositionY;
    public static  int treeNodeBaseSize;
    public static  int treeWordBaseSize;
    public static  float treeScaleBigger;
    public static  float treeScaleSmaller;

    public static void loadConfig() {
        // 读取屏幕配置
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Rectangle bounds = ge.getDefaultScreenDevice().getDefaultConfiguration().getBounds();
        int screenWidth = bounds.width;
        int screenHeight = bounds.height;
        // 读取页面尺寸配置并计算大小
        try{
            Properties properties=new Properties();
            properties.load(Config.class.getClassLoader().getResourceAsStream("huffman.properties"));
            fileChooseGUIWidth=(int)(Double.parseDouble(properties.getProperty("gui.fileChooseGUI.scale.width"))*screenWidth);
            fileChooseGUIHeight=(int)(Double.parseDouble(properties.getProperty("gui.fileChooseGUI.scale.height"))*screenHeight);
            fileDisplayGUIWidth=(int)(Double.parseDouble(properties.getProperty("gui.fileDisplayGUI.scale.width"))*screenWidth);
            fileDisplayGUIHeight=(int)(Double.parseDouble(properties.getProperty("gui.fileDisplayGUI.scale.height"))*screenHeight);
            treeDisplayGUIWidth=(int)(Double.parseDouble(properties.getProperty("gui.treeDisplayGUI.scale.width"))*screenWidth);
            treeDisplayGUIHeight=(int)(Double.parseDouble(properties.getProperty("gui.treeDisplayGUI.scale.height"))*screenHeight);
            treeBasePositionX=Integer.parseInt(properties.getProperty("huffmanTree.basePosition.x"));
            treeBasePositionY=Integer.parseInt(properties.getProperty("huffmanTree.basePosition.y"));
            treeNodeBaseSize=Integer.parseInt(properties.getProperty("huffmanTree.nodeBaseSize"));
            treeWordBaseSize=Integer.parseInt(properties.getProperty("huffmanTree.wordBaseSize"));
            treeScaleBigger=Float.parseFloat(properties.getProperty("huffmanTree.scale.bigger"));
            treeScaleSmaller=Float.parseFloat(properties.getProperty("huffmanTree.scale.smaller"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
